Next | Prev | Up | Top | Contents | Index

The Device Number Types

Two numbers are carried in the inode of a device special file: a major device number of up to 9 bits, and a minor device number of up to 18 bits. The numbers are assigned when the device special file is created, either by the /dev/MAKEDEV script or by the system administrator. The contents and meaning of device numbers is discussed under "Device Representation".

At almost every upper-half entry point, the first argument to a driver is a dev_t object, an unsigned integer containing the values of the major and minor numbers for the device that is to be used. The dev_t type is declared in sys/types.h along with types major_t and minor_t, which represent major and minor numbers as variables.


Use of the Device Numbers

You typically use the major device number to learn which device driver has been called. This is important only when a device driver supports multiple interfaces, for example when one driver represents both character and block access to the same hardware.

You use the minor device number to learn which hardware unit is being accessed. This is of interest only when a driver supports multiple units. In addition, device management options can be encoded into the minor number, as described under "Minor Device Number".


Device Number Functions

The kernel provides several functions for manipulating device numbers, and these are summarized in Table 9-1.

Functions to Manipulate Device Numbers
FunctionHeader FilesCan SleepPurpose
etoimajor(D3) ddi.hNConvert external to internal major device number.
getemajor(D3) ddi.hNGet external major device number.
geteminor(D3) ddi.hNGet external minor device number.
getmajor(D3) ddi.hNGet internal major device number.
getminor(D3) ddi.hNGet internal minor device number.
itoemajor(D3) ddi.hNConvert internal to external major device number.
makedevice(D3) ddi.hN Make device number from major and minor numbers.

The most important of these are


External and Internal Numbers

The kernel uses the major device number as a subscript to index various tables. Some variants of UNIX, in order to avoid wasting space on sparse tables, translate the major device number to an internal code. Sometimes the minor number is translated too.

This internal encoding of the device number is of no interest in IRIX. If it is done, it is done only for the purpose of subscripting tables within the kernel that are not accessible to device drivers. Internal device numbers have no utility in IRIX. However, functions related to internal device numbers are included for compatibility with SVR4.

If you are writing a new device driver specifically for IRIX, use only external device numbers. If you are porting a device driver that uses the getmajor(), getminor(), etoimajor() and etoiminor() functions, you can leave these function calls unchanged. (But if the driver attempts to access the kernel switch tables, it is nonportable and should be changed.)


Next | Prev | Up | Top | Contents | Index